#include "matcher.h"
#include "node.h"
using namespace std;

string Matcher::group(int index){        
    return getSubstr(groupSpan(index));
}

string Matcher::group(const char *name){
    return group(p->getIndexByName(name));
}

Span Matcher::groupSpan(int index){
    if(index<0 || index>p->getIndexedGroupCount())
        throw GroupNotExist("");
    if(index == 0){
        return Span(0,getLastMatchTo());
    } else {
        return capture_groups[index];
    }
}

Span Matcher::groupSpan(const char *name){
    return groupSpan(p->getIndexByName(name));
}
